/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.annuaireComp.sessions;

import fr.annuaireComp.entities.Competence;
import fr.annuaireComp.entities.CompetencePersonnel;
import fr.annuaireComp.entities.CompetencePersonnelPK;
import fr.annuaireComp.entities.Personnel;
import javax.ejb.Stateless;
import fr.annuaireComp.facades.CompetencePersonnelFacadeLocal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;

/**
 *
 * @author MiniK
 */
@Stateless
public class CompetencePersonnelManagerBean implements CompetencePersonnelManager, CompetencePersonnelLocal {

    @EJB
    private CompetencePersonnelFacadeLocal _DAL;

    @Override
    public void addPersonnelCompetence(Integer IdPersonnel, Integer IdCompetence, Integer anneesXP, String commentaire) {
        CompetencePersonnel compPers = new CompetencePersonnel(IdCompetence, IdPersonnel);
        compPers.setAnneesXp(anneesXP);
        compPers.setCommentaire(commentaire);
      
        _DAL.create(compPers);
      
    }

    @Override
    public void deletePersonnelCompetence(int idPersonnel, int idComp) {
        CompetencePersonnelPK compPersPK = new CompetencePersonnelPK(idComp, idPersonnel);
 CompetencePersonnel f = _DAL.find(compPersPK);
        _DAL.remove(f);
    }

    @Override
    public void editPersonnelCompetence(CompetencePersonnel personnelcomp) {
        _DAL.edit(personnelcomp);

    }
    
    

    @Override
    public void removeAllCompetencesOf(int idPersonnel) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("idpersonnel", idPersonnel);
        List<CompetencePersonnel> persComps = _DAL.findBy(params);
        for (CompetencePersonnel cP : persComps) {
            _DAL.remove(cP);
        }
    }

    @Override
    public List<CompetencePersonnel> listCompetencePersonnel() {
        return _DAL.findAll();
        
    }

    @Override
    public List<CompetencePersonnel> listCompetencePersonnelOf(Personnel pers) {
          Map<String, Object> params = new HashMap<String, Object>();
        params.put("personnel", pers);
     //   List<CompetencePersonnel> persComps = _DAL.findBy(params);
        return _DAL.findBy(params);
        
    }

    @Override
    public List<CompetencePersonnel> listCompetencePersonnelsByCompetence(Integer compId) {
          Map<String, Object> params = new HashMap<String, Object>();
           
        params.put("competence", new Competence(compId));
     //   List<CompetencePersonnel> persComps = _DAL.findBy(params);
        return _DAL.findBy(params);
    }

    @Override
    public List<CompetencePersonnel> listCompetencePersonnelBy(int compId, int anneesXp) {
        Map<String, Object> params = new HashMap<String, Object>();
           
        params.put("competence", new Competence(compId));
        params.put("anneesXp",anneesXp );
                
        return _DAL.findBy(params);
        
    }

    @Override
    public List<CompetencePersonnel> listCompetenceBy(Map<String,Object> params) {
       return _DAL.findBy(params);
    }
}
